<!doctype html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Default Examples</title>
		<style>
			form {
				margin: 0;
			}
			textarea {
				display: block;
			}
			[data-name=insertimages] {
				width: 100px;
				position: relative;
			}
			[data-name=insertimages]:after {
				content: "批量图片上传";
				font-size: 12px;
				font-weight: normal;
				position: absolute;
				left: 25px;
				bottom:10px;
			}
		</style>
		<link rel="stylesheet" href="../themes/default/default.css" />
		<script type="text/javascript" src="//public.k3cdn.com/jquery/1.11.1/jquery.min.js"></script>
		<script charset="utf-8" src="../kindeditor-all-min.js"></script>
		<script>
			var editor;
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					allowFileManager : true,
					uploadJson:'http://127.0.0.1:8000/php/upload_json.php?dir=image',
					fileSizeLimit:"10MB",// 前端文件大小限制
					fileUploadLimit:'30',// 全段一次上传的文件数量限制
					afterUploaded:function(data)
					{
						// 格式化批量上传返回的数据，
						// 格式化截图上传返回的数据，
						// 上传成功返回数据格式：
						// data = { error:0 ,url:''}
						// 上传失败返回数据格式：
						// data= { error:10,message:''}
						var result = {};
						if (data.code === 0){
							result.error = 0;
							result.url = data.data.url;
						}else{
							result.error = data.code;
							result.message = data.msg;
						}
						console.log('uploaded:' ,data);
						return result;
					}
				});
				K('input[name=getHtml]').click(function(e) {
					alert(editor.html());
				});
				K('input[name=isEmpty]').click(function(e) {
					alert(editor.isEmpty());
				});
				K('input[name=getText]').click(function(e) {
					alert(editor.text());
				});
				K('input[name=selectedHtml]').click(function(e) {
					alert(editor.selectedHtml());
				});
				K('input[name=setHtml]').click(function(e) {
					editor.html('<h3>Hello KindEditor</h3>');
				});
				K('input[name=setText]').click(function(e) {
					editor.text('<h3>Hello KindEditor</h3>');
				});
				K('input[name=insertHtml]').click(function(e) {
					editor.insertHtml('<strong>插入HTML</strong>');
				});
				K('input[name=appendHtml]').click(function(e) {
					editor.appendHtml('<strong>添加HTML</strong>');
				});
				K('input[name=clear]').click(function(e) {
					editor.html('');
				});
			})

			function dataURLtoBlob(dataurl) {
				var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
						bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
				while (n--) {
					u8arr[n] = bstr.charCodeAt(n);
				}
				return new Blob([u8arr], {type: mime});
			}

		</script>
	</head>
	<body>
		<h3>默认模式</h3>
		<form>
			<textarea name="content" style="width:800px;height:400px;visibility:hidden;">KindEditor</textarea>
			<p>
				<input type="button" name="getHtml" value="取得HTML" />
				<input type="button" name="isEmpty" value="判断是否为空" />
				<input type="button" name="getText" value="取得文本(包含img,embed)" />
				<input type="button" name="selectedHtml" value="取得选中HTML" />
				<br />
				<br />
				<input type="button" name="setHtml" value="设置HTML" />
				<input type="button" name="setText" value="设置文本" />
				<input type="button" name="insertHtml" value="插入HTML" />
				<input type="button" name="appendHtml" value="添加HTML" />
				<input type="button" name="clear" value="清空内容" />
				<input type="reset" name="reset" value="Reset" />
			</p>
		</form>
	</body>
</html>
